package com.example.calories;

        import androidx.appcompat.app.AppCompatActivity;

        import android.content.Intent;
        import android.database.Cursor;
        import android.database.sqlite.SQLiteDatabase;
        import android.os.Bundle;
        import android.view.View;
        import android.widget.Button;
        import android.widget.LinearLayout;
        import android.widget.TextView;

public class Main2Activity extends AppCompatActivity implements View.OnClickListener {
    private Button back;
    private TextView textView[];
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
        init();
        setText();
    }
    public void setText() {
        DatabaseHelper databaseHelper = new DatabaseHelper(this, "EX2", null, 1);
        SQLiteDatabase db = databaseHelper.getWritableDatabase();
        Cursor cursor = db.query("calories", null, null, null, null, null, null);
        int i = 0;
        while(cursor.moveToNext()) {
            String calorie = cursor.getString(cursor.getColumnIndex("calorie"));
            String times = cursor.getString(cursor.getColumnIndex("times"));
            textView[i].setText(times+":"+calorie);
            i++;
        }
    }
    public void init()
    {
        back = findViewById(R.id.back);
        back.setOnClickListener(this);
        textView = new TextView[17];
        textView[0]=findViewById(R.id.top1);
        textView[1]=findViewById(R.id.top2);
        textView[2]=findViewById(R.id.top3);
        textView[3]=findViewById(R.id.top4);
        textView[4]=findViewById(R.id.top5);
        textView[5]=findViewById(R.id.top6);
        textView[6]=findViewById(R.id.top7);
        textView[7]=findViewById(R.id.top8);
        textView[8]=findViewById(R.id.top9);
        textView[9]=findViewById(R.id.top10);
        textView[10]=findViewById(R.id.top11);
        textView[11]=findViewById(R.id.top12);
        textView[12]=findViewById(R.id.top13);
        textView[13]=findViewById(R.id.top14);
        textView[14]=findViewById(R.id.top15);
        textView[15]=findViewById(R.id.top16);
        textView[16]=findViewById(R.id.top17);
    }
    @Override
    public void onClick(View v) {
        Intent intent = new Intent(Main2Activity.this,MainActivity.class);
        startActivity(intent);
    }
}
